package com.xqboss.apps.listener;

import com.xqboss.apps.constant.RedisKey;
import com.xqboss.apps.enums.mq.AppMqDelayEnum;
import com.xqboss.apps.service.sys.SysPopupService;
import com.xqboss.common.core.mq.MqEnum;
import com.xqboss.common.core.mq.MqListener;
import org.apache.rocketmq.client.apis.consumer.ConsumeResult;
import org.apache.rocketmq.client.apis.message.MessageView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * <p>
 *     弹窗自动上架
 * </p>
 * @author Trent
 * @date 2023/9/15
 */

@Component
public class PopupSaleableListener extends MqListener {

    @Lazy
    @Autowired
    private SysPopupService popupService;

    @Override
    public MqEnum getEnum() {
        return AppMqDelayEnum.POPUP_MSG_SHOW;
    }

    @Override
    public ConsumeResult solve(MessageView message) {
        String value = StandardCharsets.UTF_8.decode(message.getBody()).toString();
        long id = Long.parseLong(value);
        popupService.autoSaleable(id);
        return ConsumeResult.SUCCESS;
    }
}
